/***************
 * Home Projects Panel
 */
AIR2.Home.Projects = function() {
// WRITER role in any organization? show the button
    var isWriter = (AIR2.USERINFO.type == 'S') ? true : false;
    Ext.iterate(AIR2.USERAUTHZ, function(uuid,role,obj) {
        if (AIR2.AUTHZ.WRITER & role) {
            isWriter = true;
            return false; // stop iterating
        }
    });
    var createButton = {};
    if (isWriter) {
        createButton = { 
            xtype: 'air2button',
            air2type: 'CLEAR',
            iconCls: 'air2-icon-add',
            tooltip: 'New project',
            handler: function() {
                AIR2.Project.Create({
                    originEl: this.el,
                    redirect: true
                });     
            }       
        };
    }
    return new AIR2.UI.Panel({
        colspan: 2,
        title: 'Projects',
        cls: 'air2-home-project',
        iconCls: 'air2-icon-project',
        showTotal: true,
        showAllLink: AIR2.HOMEURL+'/search/projects',
        tools: ['->', createButton],
        storeData: AIR2.Home.PROJDATA,
        itemSelector: '.air2-home-project-row',
        tpl: new Ext.XTemplate(
            '<table>' +
              '<tr><th>PROJECT</th><th class="right">LAST UPDATED</th>' +
                '<th class="right">CREATED</th>' +
                '<th class="right">SHARED</th></tr>' +
              '<tpl for="."><tr class="air2-home-project-row">' +
                '<td><a class="name" href="'+AIR2.HOMEURL+'/project/{prj_uuid}">{prj_display_name}</a></td>' +
                '<td align="right">{[AIR2.Format.date(values.prj_upd_dtim)]}</td>' +
                '<td align="right">{[AIR2.Format.date(values.prj_cre_dtim)]}</td>' +
                '<td align="right">{[AIR2.Format.bool(values.prj_shared_flag)]}</td>' +
              '</tr></tpl>' +
            '</table>',
            { compiled: true, disableFormats: true }
        )
    });
}
